package com.design.android.personnel.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.design.android.personnel.R;
import com.design.android.personnel.bean.PersonnelInfo;

import java.util.List;

public class PersonnelInfoItemAdapter extends ArrayAdapter<PersonnelInfo> {

    public PersonnelInfoItemAdapter(Context context, List<PersonnelInfo> values) {
        super(context, R.layout.personnel_info_item, values);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.personnel_info_item, parent, false);

        PersonnelInfo item = getItem(position);

        Bitmap avatar = item.getAvatar();
        String phone = item.getPhone();
        String username = item.getName();
        String sex = item.getSex();
        String addr = item.getAddr();

        ImageView avatarImageView = view.findViewById(R.id.avatar);
        TextView nameTextView = view.findViewById(R.id.name);
        TextView sexTextView = view.findViewById(R.id.sex);
        TextView phoneTextView = view.findViewById(R.id.phone);
        TextView addrTextView = view.findViewById(R.id.addr);

        avatarImageView.setImageBitmap(avatar);
        nameTextView.setText(username);
        sexTextView.setText(phone);
        phoneTextView.setText(sex);
        addrTextView.setText(addr);

        return view;
    }
}
